
/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"EACF6D63-3354-4D65-9A34-62C8DCFC7115"}
 */
function onShow(firstShow, event) {
	databaseManager.setAutoSave(false)
}

/**
 * Handle hide window.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"B3AAA542-A75C-4E4A-8511-9FDD1283851F"}
 */
function onHide(event) {
	databaseManager.revertEditedRecords()
	databaseManager.setAutoSave(true)
	return true
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"18F2B47D-D8FF-4FF3-8AC2-88F8F3B4D32F"}
 */
function confirmar(event) {
	globals.gTipo_doc		= utils.numberFormat(fac_cabecera_to_tipo_doc_afip.codigo,'00')
	globals.gSucursal		= utils.numberFormat(sucursal,'0000')
	globals.gCae			= cai
	globals.gFechaVtoCae	= utils.dateFormat(fecha_venc_cae,'yyyyMMdd')
	
	var $cod_final = globals.gCodigo_afip()
	
	if ($cod_final != 1)
	{
		codigo_afip = $cod_final
		fac_estado 	= 1
		if (databaseManager.saveData())
		{
			databaseManager.setAutoSave(true)
			globals.DIALOGS.showInfoDialog('Aviso','CAE cargado correctamente','OK')
			var $win = application.getWindow('FACTURA_ARREGLA')
			$win.hide()
			$win.destroy()
			forms.factura_cab_arreglo.buscarPendientes()
		}
		else
		{
			globals.DIALOGS.showWarningDialog('Aviso','Ocurrió un error inesperado. Por favor, inténtelo nuevamente','OK')
		}
	}
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"8E885799-2755-451B-A0FF-339ED219AA8C"}
 */
function cancelar(event) {
	var $win = application.getWindow('FACTURA_ARREGLA')
	$win.hide()
	$win.destroy()
}
